#ifndef _NET_MESSAGE_
#define _NET_MESSAGE_

#include "raknet\BitStream.h"
#include "raknet\RakNetTypes.h"
#include "raknet\MessageIdentifiers.h"

#include <iostream>

using namespace RakNet;
using namespace std;

enum AirMessageID
{
	AIR_SEP = ID_USER_PACKET_ENUM + 20,
	ID_JOIN,
	ID_JOIN_ACK,
	ID_EXIT,
	ID_CHANGE_TYPE,
	ID_CHANGE_SIDE,
	ID_READY,
	ID_FULL,
	ID_ALREADY_LOCK,
	ID_INFO,
	ID_INFO_INCREMENT,
	ID_NAME_DUPLICATE,
	ID_START,
	ID_ENTER,
	CLIENT_READY,
	READY_ACK,
	ID_FOBJ_INCREMENT,
	ID_FOBJ_FULL,
	ID_ARMOR_UPDATE
};

/**
* @brief record player's info who takes part in this game
*/
struct PlayerDescriptor
{
	PlayerDescriptor()
		: ready(false), confirm(false)/*, id(0)*/, flyObjectType(0), side(0), available(false), boardId(0) {}

	SystemAddress sa;
	RakString userName;
	bool ready;

	//uchar id;
	uchar flyObjectType;
	uchar side;
	uchar boardId;

	bool confirm;
	bool available;
};

struct ReadyAck//: public NetMessage
{
	static void Serialization(BitStream* bso) { bso->Write((unsigned __int8)READY_ACK); 	}
};

struct Join
{
	RakString userName;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_JOIN);
		userName.Serialize(bso);
	}
	void Deserialize(BitStream* bso)
	{
		uchar head;

		bso->Read(head);
		userName.Deserialize(bso);
	}
};

struct TChangeType
{
	uchar type;
	uchar id;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_CHANGE_TYPE);
		bso->Write(id);
		bso->Write(type);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head) {
			uchar whead = 0;
			bsi->Read(whead);
		}
		bsi->Read(id);
		bsi->Read(type);
	}
};

struct Exit
{
	uchar id;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_EXIT);
		bso->Write(id);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head)
		{
			uchar whead;
			bsi->Read(whead);
		}
		bsi->Read(id);
	}
};

struct RChangeType
{
	uchar id;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_CHANGE_TYPE);
		bso->Write(id);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head) {
			uchar whead = 0;
			bsi->Read(whead);
		}
		bsi->Read(id);
	}
};

struct RChangeSide
{
	uchar id;
	bool side;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_CHANGE_SIDE);
		bso->Write(id);
		bso->Write(side);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head)
		{
			uchar whead = 0;
			bsi->Read(whead);
		}
		bsi->Read(id);
		bsi->Read(side);
	}
};

struct TChangeSide
{
	uchar boardId;
	uchar id;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_CHANGE_SIDE);
		bso->Write(id);
		bso->Write(boardId);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head) {
			uchar whead = 0;
			bsi->Read(whead);
		}
		bsi->Read(id);
		bsi->Read(boardId);
	}
};

struct RToggleReady
{
	uchar id;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_READY);
		bso->Write(id);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head) {
			uchar whead;
			bsi->Read(whead);
		}
		bsi->Read(id);
	}
};

struct TToggleReady
{
	uchar id;
	bool ready;
	void Serialize(BitStream* bso, bool head = true)
	{
		if (head) bso->Write((uchar)ID_READY);
		bso->Write(id);
		bso->Write(ready);
	}
	void Deserialize(BitStream* bsi, bool head = true)
	{
		if (head) {
			uchar whead;
			bsi->Read(whead);
		}
		bsi->Read(id);
		bsi->Read(ready);
	}
};



#endif